function reToHouse()
{
	document.all["ListTitle"].innerHTML="监控大棚列表";
	document.all["ListOptions"].innerHTML="<a href=\"javascript:addHouse()\" class=\"action\"><img src=\"image/addhouse.gif\" />新增大棚</a>"
	document.all["house"].style.visibility="visible";
	document.all["terminal"].style.visibility="hidden";
}

// JavaScript Document
//init the store content
var terminal = new Ext.data.SimpleStore({
   fields: [
			{name:'id',type:"string"},
      		{name:'trmname',type:"string"},
			{name:"sensor",type:"string"},
			{name:"status",type:"string"},
			{name:"options",type:"string"}
     ]
    });


//init the gird	
var gridTerminal=null;   
var currTerminal;
function terminalInit(id)
{
	currTerminal=id;
	TermManager.getTerminalList(id,showTerminal); 
	//每隔30秒刷新一次
	window.setInterval(terminalReload,30000);
}
function terminalReload()
{
	TermManager.getTerminalList(currTerminal,reloadTerminalDate); 
}
function reloadTerminalDate(data)
{
	terminal.loadData(data);
	try
	{
		gridTerminal.store.reload();
	}
	catch(e)
	{
		
	}
}
function showTerminal(data)
{
	Ext.onReady(function(){

	    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
	
	    var myData =data;
	
	
	    // create the data store
	    
	    terminal.loadData(myData);
		if(gridTerminal==null)
		{
	    // create the Grid
	    gridTerminal = new Ext.grid.GridPanel({
		        store: terminal,
		        columns: [
		            {header:"终端名称",width:120, sortable: true, dataIndex: 'trmname'},
		            {header:"采集数据",width:300,sortable:true,dataIndex:'sensor'},
					{header:"运行状态",width:60,sortable:true,dataIndex:'status'},
					{header:"操作选项",width:120,sortable:false,dataIndex:'options'}
		        ],
		        stripeRows: true,
		        height:220,
		        width:624
		    });
		
		    gridTerminal.render('terminal');
		    //用户选中了一条记录,将这条记录设置为需要显示曲线的终端
		    gridTerminal.addListener('celldblclick',function(grid,row,column,e){
			var data=grid.getStore();
			var row=data.getAt(row);
			TermManager.setVip(row.get('id'),setVip_ack);
			
		})
		}
		else
		{
			try
			{
				gridTerminal.store.reload();
			}
			catch(e)
			{
				
			}
		}
		
	
	});
}
//function deleteHouse
function deleteHouse(id,name)
{
	if (confirm("您确定要删除大棚["+name+"]吗？")==true)
	{
		HouseManager.del(id,reloadDate);
	}
}
function setVip_ack()
{//刷新frame

	document.frames('drawline').location.reload();
}
function deleteTerminal(seq,name)
{
	if (confirm("您确定要删除终端["+name+"]吗？")==true)
	{
		TermManager.del(seq,delTerminal_ack);
	}		
}
function delTerminal_ack(data)
{
	alert(data);
	if (data=="操作成功")
		TermManager.getTerminalList(currTerminal,reloadTerminalDate); //这个currTerminal 实际上是大棚的id
	
}

function doActive()
{
	showProgress('正在下发激活短信……','短信发送成功');
}
function configGet()
{
	showProgress('正在发送查询消息……','消息发送成功');
}
function configset(id)
{
	window.showModalDialog("./ConfigSet.jsp?id="+id,null,"dialogWidth:400px;dialogHeight:320px");
}
